package org.xtremeobjects.domain.person;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

import org.hibernate.annotations.GenericGenerator;
import org.xtremeobjects.anotations.JavaBean;
import org.xtremeobjects.anotations.Label;
import org.xtremeobjects.anotations.PropertyChanger;
import org.xtremeobjects.anotations.state.Event;
import org.xtremeobjects.anotations.state.StateField;
import org.xtremeobjects.anotations.state.StateMachine;
import org.xtremeobjects.anotations.state.Transition;

@StateMachine(initialState="Unverified")
@Entity
@JavaBean
@Label("Email (${self.state})")
public class Email implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(generator="system-uuid")
	@GenericGenerator(name="system-uuid", strategy = "uuid")
	private String id;
	private String description;
	private String email;
	
	public enum EmailState {
		Unverified,
		Verified,
		Cancelled
	}
	
	@StateField
	private EmailState state;
	
	
	public EmailState getState() {
		return state;
	}

	@ManyToOne
	private ContactDetail contactDetail;

	private Email() {
	}

	public Email(ContactDetail detail, String description, String email) {
		this.contactDetail = detail;
		this.description = description;
		this.email = email;
	}
	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}
	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}
	/**
	 * @param email the email to set
	 */
	@PropertyChanger
	public void setEmail(String email) {
		this.email = email;
	}
	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	@Event(@Transition(from="Unverified", to="Verified"))
	public void verify() { }

	@Event(@Transition(to="Cancelled"))
	public void cancel() { }
}
